package com.caigou.modules.query.ui.sense

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseActivity
import com.caigou.comm.base.ext.screenCapture
import com.caigou.comm.base.ext.showToast
import com.caigou.comm.base.utils.MediaUtils
import com.caigou.modules.query.adpter.QueryPageAdapter
import com.caigou.modules.query.databinding.ActivitySenseBinding
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint

/**
 * @author #Suyghur.
 * Created on 2022/01/03
 */
@Route(path = RouterPath.Query.PAGE_SENSE)
@AndroidEntryPoint
class SenseActivity : BaseActivity() {

    private lateinit var binding: ActivitySenseBinding

    private val itemNames = mutableListOf(
        "生肖号码",
        "波色号码"
    )

    private val fragments = mutableListOf<Fragment>(
        ShengXiaoFragment(),
        BoSeFragment()
    )

    private val pagerAdapter: QueryPageAdapter by lazy {
        QueryPageAdapter(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySenseBinding.inflate(layoutInflater)
        setContentView(binding.root)
        containerId = binding.senseLlContainer.id
        initView()
    }

    private fun initView() {
        ARouter.getInstance().inject(this)

        pagerAdapter.setList(fragments)
        binding.senseViewPager2.adapter = pagerAdapter
        binding.senseViewPager2.isUserInputEnabled = false
        TabLayoutMediator(binding.senseTabLayout, binding.senseViewPager2, true, true) { tab, position ->
            tab.text = itemNames[position]
        }.attach()
        binding.senseViewPager2.offscreenPageLimit = itemNames.size

        binding.senseTvBack.setOnClickListener {
            finish()
        }

        binding.senseIvShare.setOnClickListener {
            val bitmap = binding.senseLlContainer.screenCapture()
            MediaUtils.saveBitmap(this, bitmap)
            showToast("截图已保存到系统相册")
        }
    }
}